﻿@{
    Layout = "~/Views/Shared/UserLayOut.cshtml";
    var myaddresslist = ViewData["myaddresslist"] as List<OrderAddress>;
}
<link rel="stylesheet" href="/scripts/ui/skins/Aqua/css/ligerui-all.css" />
<script type="text/javascript" src="/scripts/ui/js/ligerBuild.min.js"></script>
@using MiniWeb.Core.Entities
@using MiniWeb.Web.Controllers.Web.usercenter.ViewModels
@model WebSaveOrderAddress
<style>
    #info_form .input
    {
        border: 1px solid #ccc;
        width: 200px;
        height: 25px;
        line-height: 25px;
    }
    #info_form .text
    {
        border: 1px solid #ccc;
        width: 200px;
        height: 25px;
        line-height: 25px;
    }
    #info_form select
    {
        border: 1px solid #ccc;
        width: 100px;
        height: 25px;
        line-height: 25px;
    }
    #info_form textarea
    {
        border: 1px solid #ccc;
    }
    #info_form .btn_submit
    {
        height: 30px;
        line-height: 30px;
        width: 80px;
    }
</style>
<link rel="stylesheet" href="/css/validate.css">
<script type="text/javascript" src="/scripts/jquery/jquery.form.js"></script>
<script type="text/javascript" src="/scripts/jquery/jquery.validate.min.js"></script>
<script type="text/javascript" src="/scripts/jquery/messages_cn.js"></script>
<script type="text/javascript" src="/templates/speciality/js/area.js"></script>
<script type="text/javascript">
    function delAddress(id) {
        if (!confirm("您确认要删除本条收货地址吗？") || id == "") {
            return false;
        }
        $.ajax({
            type: "post",
            url: "/usercenter/deleteaddress",
            data: { id: id },
            dataType: "json",
            beforeSend: function (XMLHttpRequest) {
                //发送前动作
            },
            success: function (data, textStatus) {
                if (data.msg == 1) {
                    $.ligerDialog.success(data.msgbox);
                    location.reload();
                } else {
                    $.ligerDialog.warn(data.msgbox);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("状态：" + textStatus + "；出错提示：" + errorThrown);
            },
            timeout: 20000
        });
        return false;
    };
   
    $(function () {
        //初始化表单
        
        AjaxInitForm('info_form', 'btnSubmit', 1);
        $("#btnSubmit").bind("click", function () {
            if ($("#txtRealName").val() == "") {
                $.ligerDialog.warn('对不起，请输入收货人姓名！');
                return false;
            }
            if ($("#txtProvince").val() == "") {
                $.ligerDialog.warn('对不起，请选择所属省份！');
                return false;
            }
            if ($("#txtCity").val() == "") {
                $.ligerDialog.warn('对不起，请选择所属城市！');
                return false;
            }
            if ($("#txtArea").val() == "") {
                $.ligerDialog.warn('对不起，请选择所属区域！');
                return false;
            }
            if ($("#txtAddress").val() == "") {
                $.ligerDialog.warn('对不起，请输入街道地址！');
                return false;
            }
            if ($("#txtMobile").val() == "" && $("#txtPhone").val() == "") {
                $.ligerDialog.warn('对不起，电话和手机必须选填一项！');
                return false;
            }

        });
        $("#txtProvince").change(function () {                                   //更改省份
            change_province($(this).val());
        });
        $("#txtCity").change(function () {                                       //更改城市
            change_city($(this).val());
        });

        load_province(22);
        change_province(22, 234);
        change_city(234, 0);

    });
</script>
<div class="right m-personal">
    <div class="status-tit">
        <h2>
            收货地址</h2>
        <span></span>
    </div>
    <div class="sub-personal information clear">
        <form name="info_form" id="info_form" url="/usercenter/saveaddress">
        <input type="hidden" name="ID" value="@Model.ID"/>
        <div class="address bt20">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tbody>
                    <tr>
                        <td class="rt font_yellow2" width="15%">
                            <b>
                                @if (string.IsNullOrEmpty(Request.QueryString["id"]))
                                {
                                    <text>新增收货地址</text>
                                }
                                else
                                {
                                    <text>编辑收货地址</text>
                                }</b>
                        </td>
                        <td class="lt" width="85%">
                            电话、手机号选填一项，其余均为必选项
                        </td>
                    </tr>
                    <tr>
                        <td class="rt">
                            收货人姓名：
                        </td>
                        <td class="lt">
                            <input class="text required " name="RealName" id="txtRealName" type="text" value="@Model.RealName"><span
                                class="font_red warn">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="rt">
                            所在地区：
                        </td>
                        <td class="lt">
                            <select name="Sheng" id="txtProvince">
                                <option value="" selected="">请选择省份</option>
                            </select><select name="City" id="txtCity">
                                <option value="">请选择城市</option>
                            </select><select name="Qu" id="txtArea">
                                <option value="">请选择区域</option>
                            </select><span class="font_red warn">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="rt">
                            街道地址：
                        </td>
                        <td class="lt">
                            <textarea name="Address" id="txtAddress" class="required" cols="" rows="3">@Model.Address</textarea><span
                                class="font_red warn">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="rt">
                            邮政编码：
                        </td>
                        <td class="lt">
                            <input class="text required" name="StmpCode" id="txtPostCode" value="@Model.StmpCode" type="text"><span
                                class="font_red warn">*</span><span class="font_gary">大陆以外地区可不填写</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="rt">
                            手机号码：
                        </td>
                        <td class="lt">
                            <input class="text" name="Phone" id="txtMobile" value="@Model.Phone" type="text"><span
                                class="font_gary">&nbsp;电话号码、手机号码必填一项</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="rt">
                            电话号码：
                        </td>
                        <td class="lt">
                            <input class="text" name="Tel" id="txtPhone" value="@Model.Tel" type="text"><span
                                class="font_gary">&nbsp;区号-电话号码-分机</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="rt">
                            设为默认：
                        </td>
                        <td class="lt">
                          <input type="checkbox" name="IsDefault"  id="IsDefault" @(Model.IsDefault ? "checked='checked'" : "") />
                        </td>
                    </tr>
                    <tr>
                        <td class="rt">
                        </td>
                        <td class="lt">
                            <input name="btnSubmit" id="btnSubmit" type="submit" class="btn_submit" value="确认">
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        </form>
        <p class="font_yellow2 bt5">
            <b>已保存的有效地址</b></p>
        <div class="saveaddress bt5">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tbody>
                    <tr>
                        <th width="10%">
                            收货人
                        </th>
                        <th width="15%">
                            所在地区
                        </th>
                        <th width="35%">
                            街道地址
                        </th>
                        <th width="10%">
                            邮编
                        </th>
                        <th width="10%">
                            电话/手机
                        </th>
                        <th width="20%">
                            操作
                        </th>
                    </tr>
                    @foreach (var item in myaddresslist)
                    {
                        <tr style="@(item.IsDefault ? "color:		#FF8040" : "")">
                            <td>
                               @(item.IsDefault ? "默认" : "")&nbsp;@item.RealName
                            </td>
                            <td>
                                <span id="p14@(item.ID)"></span><span id="c14@(item.ID)"></span><span id="a14@(item.ID)"></span>
                            </td>
                            <td class="lt">
                                @item.Address
                            </td>
                            <td>
                                @item.StmpCode
                            </td>
                            <td>
                                @item.Tel @item.Phone
                            </td>
                            <td>
                                <a class="font_blue" href="/usercenter/address?id=@item.ID">修改</a>&nbsp; <a class="font_blue" href="javascript:void(0);" onclick="delAddress(@item.ID)">
                                    删除</a>&nbsp;<a class="font_blue" href="/usercenter/SetDefaultAddress?id=@item.ID">默认</a>
                            </td>
                        </tr>
                         <script type="text/javascript">
                             load_p(@item.Sheng, "p14@(item.ID)");
                             load_c(@item.Sheng, @item.City, "c14@(item.ID)");
                             load_a(@item.City, @item.Qu, "a14@(item.ID)");
                      
                    </script>
                    }
                   
                </tbody>
            </table>
        </div>
    </div>
</div>
